﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="load_working.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Working.load_working" %>
<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        var get_week = new TblWeekController().FetchAll().Where(x => x.Id == this.id).Single();
        var get_working = new TblWorkingController().FetchAll().Where(x => x.Week == this.id);
        DateTime update = DateTime.Parse(get_week.UpdateDate.ToString());
        DateTime start = DateTime.Parse(get_week.Monday.ToString());
        DateTime End = start.AddDays(6);
        DateTime temp = start;
         %>
    <header class="w3-row w3-padding-4 w3-center w3-deep-orange">
                <%if (get_last_week(this.id) != 0)
    { %>
                <a onclick="load_week(<%=get_last_week(this.id) %>)" href="javascript:;" title="Tuần trước" class="weekly-work-slide-btn w3-text-white w3-left"><i class="fa fa-chevron-left"></i></a>
                <%} %>
                <%if (get_next_week(this.id) != 0)
    { %>
                <a onclick="load_week(<%=get_next_week(this.id) %>)" href="javascript:;" title="Tuần sau" class="weekly-work-slide-btn w3-text-white w3-right"><i class="fa fa-chevron-right"></i></a>
                <%} %>
                <span class="weekly-work-header-text">LỊCH LÀM VIỆC <%=get_week.Year%> Tuần <%=get_week.Week%> (<%=start.Day%>/<%=start.Month%>/<%=start.Year%> - <%=End.Day%>/<%=End.Month%>/<%=End.Year%>)</span><br />
                <span class="weekly-work-update-text">(Cập nhật ngày <%=update.Day%>/<%=update.Month%>/<%=update.Year%>)</span>
            </header>
            <div class="weekly-work-table w3-responsive">
                <table class="w3-table w3-white w3-bordered w3-centered w3-striped">
                    <thead>
                        <tr class="w3-teal">
                            <td class="w3-hide-small w3-hide-medium">Giáo viên</td>
                            <td>Giờ làm</td>
                            <td>Thứ 2 (<%=temp.Day%>/<%=temp.Month%>)</td>
                            <%for (int i = 1; i < 7; i++)
    {%>

                            <%
    if (temp.AddDays(i).DayOfWeek == DayOfWeek.Sunday)
    {%>
                            <td>Chủ Nhật (<%=temp.AddDays(i).Day%>/<%=temp.AddDays(i).Month%>)</td>
                            <%}
    else
    {
        int day = (int)temp.AddDays(i).DayOfWeek;%>
                            <td>Thứ <%=day += 1%> (<%=temp.AddDays(i).Day%>/<%=temp.AddDays(i).Month%>)</td>
                            <%}
    }%>
                        </tr>
                    </thead>
                    <tbody>
                        <%
    var get_staff = new TblManagerController().FetchAll().Where(x => x.Role == 2 && x.Active == true);
    foreach (TblManager staff in get_staff)
    {
        var get_work = new TblWorkingController().FetchAll().Where(x => x.Manager == staff.ManagerId && x.Week == id).ToList();
        string time = "&nbsp;", mon = "&nbsp;", tue = "&nbsp;", thu = "&nbsp;", wed = "&nbsp;", fri = "&nbsp;", sat = "&nbsp;", sun = "&nbsp;";
        int row_id = 0;
        if (get_work.Count > 0)
        {
            if (!string.IsNullOrEmpty(get_work[0].Time))
                time = get_work[0].Time;
            if (!string.IsNullOrEmpty(get_work[0].Monday))
                mon = get_work[0].Monday;
            if (!string.IsNullOrEmpty(get_work[0].Tuesday))
                tue = get_work[0].Tuesday;
            if (!string.IsNullOrEmpty(get_work[0].Wednesday))
                wed = get_work[0].Wednesday;
            if (!string.IsNullOrEmpty(get_work[0].Friday))
                fri = get_work[0].Friday;
            if (!string.IsNullOrEmpty(get_work[0].Thursday))
                thu = get_work[0].Thursday;
            if (!string.IsNullOrEmpty(get_work[0].Saturday))
                sat = get_work[0].Saturday;
            if (!string.IsNullOrEmpty(get_work[0].Sunday))
                sun = get_work[0].Sunday;
            if (!string.IsNullOrEmpty(get_work[0].Id.ToString()))
                row_id = get_work[0].Id;
        }
                        %>
                        <tr class="w3-hide-large w3-border-bottom w3-border-top w3-border-teal">
                            <td colspan="8"><%=staff.FullName%></td>
                        </tr>
                        <tr class="row_work">
                            <td rowspan="6" class="w3-white w3-border-right w3-hide-small w3-hide-medium">
                                <span class="w3-hide row_id"><%=row_id%></span>
                                <span class="w3-hide manager_id"><%=staff.ManagerId%></span>
                                <img src="../Content/avatar/<%=staff.Avatar%>" class="weekly-work-img" /><br />
                                <div class="w3-padding-8"><%=staff.FullName%></div>
                            </td>
                            <td class="work_time work"><%=time%></td>
                            <td class="work_mon work"><%=mon%></td>
                            <td class="work_tue work"><%=tue%></td>
                            <td class="work_wed work"><%=wed%></td>
                            <td class="work_thu work"><%=thu%></td>
                            <td class="work_fri work"><%=fri%></td>
                            <td class="work_sat work"><%=sat%></td>
                            <td class="work_sun work"><%=sun%></td>
                        </tr>

                        <%
                            for (int i = 1; i < 6; i++)
                            {
                                string time1 = "&nbsp;", mon1 = "&nbsp;", tue1 = "&nbsp;", thu1 = "&nbsp;", wed1 = "&nbsp;", fri1 = "&nbsp;", sat1 = "&nbsp;", sun1 = "&nbsp;";
                                int row_id1 = 0;
                                if (get_work.Count > i)
                                {
                                    if (!string.IsNullOrEmpty(get_work[i].Time))
                                        time1 = get_work[i].Time;
                                    if (!string.IsNullOrEmpty(get_work[i].Monday))
                                        mon1 = get_work[i].Monday;
                                    if (!string.IsNullOrEmpty(get_work[i].Tuesday))
                                        tue1 = get_work[i].Tuesday;
                                    if (!string.IsNullOrEmpty(get_work[i].Wednesday))
                                        wed1 = get_work[i].Wednesday;
                                    if (!string.IsNullOrEmpty(get_work[i].Friday))
                                        fri1 = get_work[i].Friday;
                                    if (!string.IsNullOrEmpty(get_work[i].Thursday))
                                        thu1 = get_work[i].Thursday;
                                    if (!string.IsNullOrEmpty(get_work[i].Saturday))
                                        sat1 = get_work[i].Saturday;
                                    if (!string.IsNullOrEmpty(get_work[i].Sunday))
                                        sun1 = get_work[i].Sunday;
                                    if (!string.IsNullOrEmpty(get_work[i].Id.ToString()))
                                        row_id1 = get_work[i].Id;
                                }
                        %>
                        <tr class="row_work">
                            <td class="w3-hide manager_id"><%=staff.ManagerId%></td>
                            <td class="w3-hide row_id"><%=row_id1%></td>
                            <td class="work_time work"><%=time1%></td>
                            <td class="work_mon work"><%=mon1%></td>
                            <td class="work_tue work"><%=tue1%></td>
                            <td class="work_wed work"><%=wed1%></td>
                            <td class="work_thu work"><%=thu1%></td>
                            <td class="work_fri work"><%=fri1%></td>
                            <td class="work_sat work"><%=sat1%></td>
                            <td class="work_sun work"><%=sun1%></td>
                        </tr>
                        <%}%>

                        <%} %>
                    </tbody>
                </table>
            </div>
</body>
</html>
